<template>
	<view class="base-cloud">
		
		<!--主页：100%宽100%高，带分页-->
		<block v-if="!this.issider">
		<view class="h100p w100p whiteBg  mt10  rds5">				
			<view class="fz16  pd10 bold  brown bb">{{ title }}</view>
				<view class="grid g4 pd10 w100p">
					
					
					
				
			<block v-for="(x , index) in page.list" :key="index">		
					<view class="w25p h160 pd10">
						<image :src="x.avatar" class="w100p hover h140" @click="godetail(x._id)"></image>
						<text class="tc clip bold hover" @click="godetail(x._id)">{{x.title}}</text>
					</view>
					
					<!-- <view class="fz20 black clip pd10 text-bold hover brown" @click="godetail(x._id)">
						<text class="greenBg pd5 fz16 rds5 mr5" v-if="x.category_id">{{x.category_id}}</text> 
						{{x.title}} </view>
					<view class="fz16 grey clip pl10 ">{{x.createTimeStr}}</view>
					<view class="fz16 gray clip2 bb pd10  ">{{x.excerpt}}</view> -->
			</block>
			</view>
			<block v-if="page.list.length==0">
				<view class="fz20 brown clip pd10 tc ">{{message}}</view>
			</block>
			<view class="mt10" v-if="this.showPager">
			<paginate :page="page" :showPageSize="true" @switchPage="changePaginate"></paginate>
			</view>
		</view>
		</block>
		<block v-if="this.issider">
		<view class="h100p w100p whiteBg shadow pd10 mt10 rds5">		
			
			<view class="fz16  pd10 bold  brown bb">			
			{{ title }} </view>
			
		
				<block v-for="(x , index) in page.list" :key="index">		
					<view class="fz14 clip pt15 hover " @click="godetail(x._id)">{{index+1}}. {{x.title}}</view>										
				</block>
					
		</view>
		</block>
	</view>
</template>

<script>
	import paginate from '@/components/paginate/paginate.vue';
	export default {
		name: 'kenyNewsList',
		components: {paginate},
		props: {
			title: {
				type: String,
				default: '所有图片'
			}, // 列表标题
			istop: {
				type: [Boolean, String],
				default: false
			}, // 是否置顶
			ishot: {
				// 是否热门推荐
				type: [Boolean, String],
				default: false
			},
			showPager: {
				// 是否显示分页
				type: [Boolean, String],
				default: true
			},
			issider: {
				// 是否边部文章列表
				type: [Boolean, String],
				default: false
			},
			pageNumber:{
				type:[Number,String],
				default: 1
			},
			pageSize:{
				type:[Number,String],
				default: 24
			},
			actionUrl:{
				type: String,
				default: 'api/article/list'
			},
			category_id:{
				type:String,
				default: ''
			},
			mode:{
				type:[Number,String],
				default: ''
			},
			keywords:{
				type:String,
				default: ''
			},
		},
		data() {
			return {				
				conditions: {"article_status":1,"mode":2},
				loading: true ,	
				
				page: {
					pageNumber: this.pageNumber,
					lastPage: true,
					totalPage: 1,
					list: [],
					totalRow: 0,
					pageSize: this.pageSize
				},
				message:'',
				messagelist:["正在加载...","找不到任何记录"],
			}
		},		
		
		beforeCreate() {
			//this.conditions = this.params ;
			//console.log("beforeCreate")
		},
		created() {
			if(this.category_id){
				this.conditions = Object.assign(this.conditions,{"category_id":this.category_id}) ;
			}
			if(this.mode){
				this.conditions = Object.assign(this.conditions,{"mode":this.mode}) ;
			}
			if(this.keywords){
				this.conditions = Object.assign(this.conditions,{"title":this.keywords}) ;
				//this.conditions = Object.assign(this.conditions,{"excerpt":this.keywords}) ;
				
			}
			if(this.istop){ //是否置顶
				this.conditions = Object.assign(this.conditions,{"is_sticky":true}) ;
			}
			if(this.ishot){//是否热门推荐
				this.conditions = Object.assign(this.conditions,{"is_essence":true}) ;
			}
			//console.log(JSON.stringify(this.conditions))
			var that = this ;
			this.getPage();
		},
		
		methods: {
			getPage:function(e){
				this.message=this.messagelist[0];
				this.bcc.callInCache({
					url : this.actionUrl ,
					data : {
						...this.conditions,
						pageNumber : this.page.pageNumber ,
						pageSize : this.page.pageSize 
					},
					success : e => {
						uni.hideLoading();
						
						e.page.list = e.page.list.map(item=>{
							item.createTimeStr = this.bcc.date.toStr(item.publish_date);
							return item ;
						});
						this.page = e.page ;
						// this.conditonList[1].list = e.statusList ;
						this.loading = false ;
						this.message=this.messagelist[1];
					}
				});
			},
			
			submitSearch:function(e){
				this.conditions = e.conditions ;
				this.switchPage();
			},
			
			switchPage: function(pageNumber) {
				uni.showLoading({
					title:"加载中…"
				});
				this.page.pageNumber = pageNumber || this.page.pageNumber ;
				this.getPage();
			},
			
			changePaginate: function(e) {
				this.page.pageSize = e.pageSize ;
				this.page.pageNumber = e.pageNumber ;
				this.switchPage();
			},
			godetail(id){
				uni.navigateTo({
					url:'../../pages/web/artpage?id='+id
					
				})
			}
			
			
		}
	}
</script>
